<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    //求数组和与平均值
    /*  var sum = 0;
     var arr = [2, 6, 1, 7, 4];
     var average = 0;
     for (var i = 0; i < arr.length; i++) {
         sum += arr[i];
     }
     console.log(sum);
     average = sum / arr.length;
     console.log(average); */



    //数组最大值
    /*     var arr = [2, 6, 1, 77, 52, 25, 7];
        var max = arr[0];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        alert(max); */



    //数组转换为分割字符串
    /* var arr = ['red', 'green', 'blue'];
    var str = '';
    var sep = '|';
    for (var i = 0; i < arr.length; i++) {
        str += arr[i] + sep;
    }
    console.log(str); */

    //数组新增元素
    /*  var arr = [];
     for (var i = 0; i < 10; i++) {
         arr[i] = i + 1;
     }
     console.log(arr); */



    //筛选数组
    //方法1：
    /*     var arr = [2, 0, 3, 12, 15, 11, 9, 8];
        var newArr = [];
        var j = 0;
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] > 10) {
                newArr[j] = arr[i];
                j++;
            }
        }
        console.log(newArr); */
    //方法2：  length自动检测长度变化
    /* var arr = [2, 0, 3, 12, 15, 11, 9, 8];
    var newArr = [];
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] > 10) {
            newArr[newArr.length] = arr[i];
        }
    }
    console.log(newArr); */




    //数组案例：1删除数组元素
    /*   var arr = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
      var newArr = [];
      for (var i = 0; i < arr.length; i++) {
          if (arr[i] != 0) {
              newArr[newArr.length] = arr[i];
          }
      }
      console.log(newArr); */
    //2翻转数组
    /*     var arr = [1, 2, 3, 4, 5];
        var newArr = [];
        for (var i = arr.length - 1; i >= 0; i--) {
            newArr[newArr.length] = arr[i];
        }
        console.log(newArr); */
    //3冒泡排序
    /*     var arr = [5, 3, 4, 2, 1]
        for (var i = 0; i <= arr.length - 1; i++) {
            for (var j = 0; j <= arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    var temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        console.log(arr); */



    //计算器
    /* var arr = [];
    for (var i = 0; i <= 100; i++) {
        var num = prompt(
            '欢迎使用简易计算器：\n 1.加法运算\n 2.减法运算\n 3.乘法运算\n 4.除法运算\n 5.退出\n 请输入你需要的操作：'
        )
        num = parseFloat(num);
        switch (num) {
            case 1:
                arr[1] = prompt('请输入第一个数：');
                arr[2] = prompt('请输入第二个数：');
                var sum = parseFloat(arr[1]) + parseFloat(arr[2]);
                alert(arr[1] + '+' + arr[2] + '=' + sum);
                break;
            case 2:
                arr[1] = prompt('请输入第一个数：');
                arr[2] = prompt('请输入第二个数：');
                var jian = parseFloat(arr[1]) - parseFloat(arr[2]);
                alert(arr[1] + '-' + arr[2] + '=' + jian);
                break;
            case 3:
                arr[1] = prompt('请输入第一个数：');
                arr[2] = prompt('请输入第二个数：');
                var cheng = parseFloat(arr[1]) * parseFloat(arr[2]);
                alert(arr[1] + '×' + arr[2] + '=' + cheng);
                break;
            case 4:
                arr[1] = prompt('请输入第一个数：');
                arr[2] = prompt('请输入第二个数：');
                var chu = parseFloat(arr[1]) / parseFloat(arr[2]);
                alert(arr[1] + '÷' + arr[2] + '=' + chu);
                break;
            case 5:
                alert('退出成功');
                i = 101;
                break;
            default:
                alert('请输入正确的选项');
        }
    } */
</script>

<body>

</body>

</html>